package com.corechina.apex_osswords.domain.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.corechina.apex_osswords.domain.entity.SysUser;
import com.corechina.apex_osswords.domain.vo.SysLoginInfoVo;
import com.corechina.apex_osswords.domain.vo.SysUserForTokenVo;
import com.corechina.apex_osswords.domain.vo.SysUserVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface SysUserMapper extends BaseMapper<SysUser> {

    int updateByPrimaryKey(SysUser sysUser);

    SysUserVo getOne(@Param("id") Integer id);

    @Update("update sys_user set pwd = #{pwd} where id = #{id}")
    int updatePwd(@Param("pwd") String pwd, @Param("id") Integer id);

    @Update("update sys_user set enabled = #{enabled} where id = #{id}")
    int updateEnabled(@Param("id") Integer id, @Param("enabled") Integer enabled);

    @Select("select " +
            "sm.perms " +
            "from sys_user su " +
            "left join sys_user_groups_menu gm on gm.group_id = su.group_id " +
            "left join sys_menu sm on sm.id = gm.menu_id " +
            "where su.id = #{userId}"
    )
    List<String> getAllPerms(Integer userId);

    SysUserForTokenVo getUserInfoForToken(@Param("userId") Integer userId);

    IPage<SysUserVo> getUserAllList(Page page, @Param("userName") String userName);

    SysLoginInfoVo getUserInfoByLoginName(@Param("loginName") String loginName);

    @Select("select * from sys_user")
    List<SysUser> getList();

}
